package handler

import (
	"api/basic/global"
	"api/internal/model"
	"github.com/gin-gonic/gin"
	"log"
)

func NotifyPay(c *gin.Context) {

	err := c.Request.ParseForm()
	if err != nil {
		return
	}

	outTradeNo := c.Request.PostForm["out_trade_no"]
	tradeStatus := c.Request.PostForm["trade_status"]

	log.Printf("回调参数为%v,%v", outTradeNo, tradeStatus)

	order := model.Order{}
	err = global.DB.Debug().Model(&model.Order{}).Where("order_sn = ?", outTradeNo).Find(&order).Error
	if err != nil {
		return
	}

	err = global.DB.Debug().Model(&model.Order{}).Where("order_sn = ?", outTradeNo).Update("status", 1).Error
	if err != nil {
		return
	}
}
